<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
    <style>

    </style>
</head>

<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="search"  placeholder="请输入搜索内容" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">日期:</div>
                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="createTime" placeholder="请选择日期">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">会话类型:</div>
                    <div class="layui-form-item layui-inline">

                        <div>
                            <select name="contentType" lay-verify="" style="width: 200px;">
                                <option value="">请选择会话类型</option>
                                <option value="1">文本</option>
                                <option value="2">语音</option>
                                <option value="3">图片</option>
                                <option value="4">位置</option>
                                <option value="5">文件</option>
                                <option value="6">视频</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">消息类型:</div>
                    <div class="layui-form-item layui-inline">
                        <div>
                            <select name="type" lay-verify="" style="width: 200px;">
                                <option value="">请选消息类型</option>
                                <option value="0">单聊</option>
                                <option value="1">群聊</option>
                                <option value="2">聊天室</option>
                                <option value="3">频道</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="yhxx-query">
                            <i class="layui-icon layui-icon-search"></i>
                            搜索
                        </button>
                    </div>

                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="yhxx-table" lay-filter="yhxx-table"></table>
        </div>
    </div>

    <script type="text/html" id="yhxx-bar">
        <button class="pear-btn pear-btn-sm" lay-event="retract">撤回</button>
		</script>

    <script type="text/html" id="avatar-tpl">
			<img src="{{d.avatar}}"/>
   </script>
    <script type="text/html" id="createTime-tpl">
    {{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}
</script>

    <script src="../../component/layui/layui.js"></script>
    <script src="../../component/pear/pear.js"></script>
    <script>
        layui.use(['table', 'laydate', 'form', 'jquery'], function () {
            let table = layui.table;
            let form = layui.form;
            let $ = layui.jquery;
            var laydate = layui.laydate;

            //年月选择器
            laydate.render({
                elem: '#createTime'
                , type: 'month'
            });

            let cols = [
                [{
                    type: 'checkbox'
                },
                {
                    title: '序号',
                    field: 'id',
                    align: 'center',
                    width: 100
                },
                {
                    title: '会话类型',
                    field: 'contentType',
                    align: 'center',
                    templet: function (data) {
                        if (data.contentType == 0) {
                            return '<span>未知</span>'
                        } else if (data.contentType == 1) {
                            return '<span>文本</span>'
                        } else if (data.contentType == 2) {
                            return '<span>语音</span>'
                        } else if (data.contentType == 3) {
                            return '<span>图片</span>'
                        } else if (data.contentType == 4) {
                            return '<span>位置</span>'
                        } else if (data.contentType == 5) {
                            return '<span>文件</span>'
                        } else if (data.contentType == 6) {
                            return '<span>视频</span>'
                        } else if (data.contentType == 7) {
                            return '<span>动态表情</span>'
                        } else if (data.contentType == 8) {
                            return '<span>图文</span>'
                        } else if (data.contentType == 80) {
                            return '<span>撤回</span>'
                        } else if (data.contentType == 90) {
                            return '<span>提醒</span>'
                        } else if (data.contentType == 91) {
                            return '<span>正在输入提醒</span>'
                        } else if (data.contentType == 104) {
                            return '<span>创建群组</span>'
                        } else if (data.contentType == 105) {
                            return '<span>添加群组成员</span>'
                        } else if (data.contentType == 106) {
                            return '<span>移出群组成员</span>'
                        } else if (data.contentType == 107) {
                            return '<span>退出群组</span>'
                        } else if (data.contentType == 108) {
                            return '<span>解散群组</span>'
                        } else if (data.contentType == 109) {
                            return '<span>转让群组</span>'
                        } else if (data.contentType == 110) {
                            return '<span>修改群组名称</span>'
                        } else if (data.contentType == 111) {
                            return '<span>修改群昵称</span>'
                        } else if (data.contentType == 112) {
                            return '<span>修改群头像</span>'
                        } else if (data.contentType == 400) {
                            return '<span>网络电话发起</span>'
                        } else if (data.contentType == 402) {
                            return '<span>网络电话结束</span>'
                        } else if (data.contentType == 401) {
                            return '<span>网络电话接听</span>'
                        } else if (data.contentType == 403) {
                            return '<span>网络电话信令</span>'
                        } else if (data.contentType == 404) {
                            return '<span>网络电话变更</span>'
                        }



                    }
                },
                {
                    title: '消息类型',
                    field: 'type',
                    align: 'center',
                    templet: function (data) {
                        if (data.type == 0) {
                            return '<span>单聊</span>'
                        } else if (data.type == 1) {
                            return '<span>群聊</span>'
                        } else if (data.type == 2) {
                            return '<span>聊天室</span>'
                        } else {
                            return '<span>频道</span>'
                        }

                    }

                },
                {
                    title: '发送者ID',
                    field: 'fromID',
                    align: 'center',

                },
                {
                    title: '接收者ID',
                    field: 'targetID',
                    align: 'center',
                },
                {
                    title: '发送者昵称',
                    field: 'fromName',
                    align: 'center',
                },
                {
                    title: '接收者昵称',
                    field: 'targetName',
                    align: 'center',
                },
                {
                    title: '内容',
                    field: 'serachContent',
                    align: 'center',
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    templet: "#createTime-tpl"
                },
                {
                    title: '操作',
                    toolbar: '#yhxx-bar',
                    align: 'center',
                    width: 130
                }
                ]
            ]

            table.render({
                elem: '#yhxx-table',
                url: '/api/messages/xxlb/list',
                page: true,
                cols: cols,
                skin: 'line',
                toolbar: '#yhxx-toolbar',
                defaultToolbar: [{
                    layEvent: 'refresh',
                    icon: 'layui-icon-refresh',
                }, 'filter', 'print', 'exports']
            });

            table.on('tool(yhxx-table)', function (obj) {
                if (obj.event === 'remove') {
                    window.remove(obj);
                } else if (obj.event === 'retract') {
                    window.retract(obj);
                }
            });

            table.on('toolbar(yhxx-table)', function (obj) {
                if (obj.event === 'refresh') {
                    window.refresh();
                }
            });

            form.on('submit(yhxx-query)', function (data) {
                data.field.createTime = $("#createTime").val();
                console.log(JSON.stringify(data))
                table.reload('yhxx-table', {
                    where: data.field
                })
                return false;
            });

            form.on('switch(yhxx-enable)', function (obj) {
                layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
            });

            window.add = function () {
                layer.open({
                    type: 2,
                    title: '新增',
                    shade: 0.1,
                    area: ['500px', '400px'],
                    content: MODULE_PATH + 'add.html'
                });
            }

            window.retract = function (obj) {

                layer.confirm('确定要撤回本条消息吗？', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.close(index);
                    let loading = layer.load();
                    $.ajax({
                        url: "/api/messages/retract/" + obj.data.fromID + "/" + obj.data.mid,
                        dataType: 'json',
                        success: function (result) {
                            layer.close(loading);
                            if (result.code == 0) {
                                layer.msg(result.msg, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    table.reload('yhxx-table');
                                });
                            } else {
                                layer.msg(result.msg, {
                                    icon: 2,
                                    time: 1000
                                });
                            }
                        }
                    })
                });
            }
   

            window.refresh = function (param) {
                table.reload('yhxx-table');
            }
        })
    </script>
</body>

</html>